﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ResourceFunList.aspx.cs"
    Inherits="Atomic.Web.Pages.Sys.ResourceFunList" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript" language="javascript">
        $(function () {
            var FormID = '<%=Request["FormID"] %>';
            $('#resourceFunList').datagrid({
                url: '/Handlers/Sys/ResourceHandler.ashx/?method=GetResourceFunList',
                singleSelect: true,
                queryParams: {
                    FormID: FormID
                },
                frozenColumns: [[
	                { field: 'ID', title: '编号', width: 60 },
	                { field: 'Name', title: '功能名', width: 150 },
                    { field: 'Key', title: '唯一键', width: 150 },
                    { field: 'Enabled', title: '启用', width: 50,
                        formatter: function (v) {
                            if (v) {
                                return '是';
                            } else {
                                return '<span style="color:#f00;">否<span>';
                            }
                        }
                    }
                ]],
                toolbar: [
                    {
                        text: '新建',
                        iconCls: 'icon-add',
                        handler: function () {
                            $('#resourceFunEditorWindow').window('open');
                            $('#resourceFunEditorWindow').window('refresh', 'ResourceFunEditor.aspx?FormID=' + FormID);
                        }
                    },
                    {
                        text: '编辑',
                        iconCls: 'icon-edit',
                        handler: function () {
                            var selectedNode = $('#resourceFunList').datagrid('getSelected');
                            if (selectedNode == null) {
                                $.messager.alert('提示信息', '请选择需要编辑的项', 'info');
                                return;
                            }
                            $('#resourceFunEditorWindow').window('open');
                            $('#resourceFunEditorWindow').window('refresh', 'ResourceFunEditor.aspx?FormID=' + FormID + '&ID=' + selectedNode.ID);
                        }
                    },
                    {
                        text: '删除',
                        iconCls: 'icon-remove',
                        handler: function () {
                            var selectedNode = $('#resourceFunList').datagrid('getSelected');
                            if (selectedNode == null) {
                                $.messager.alert('提示信息', '请选择需要删除的项', 'info');
                                return;
                            }
                            $.messager.confirm('提示信息', '确定删除选中项？', function (b) {
                                if (b) {
                                    //提交删除
                                    $.post('/Handlers/Sys/ResourceHandler.ashx/?method=RemoveResourceFun',
                                    {
                                        ID: selectedNode.ID
                                    },
                                    function (data) {
                                        if (data.Success) {
                                            $('#resourceFunList').datagrid('reload');
                                        } else {
                                            $.messager.alert('提示信息', data.Message, 'info');
                                        }
                                    },
                                    'json');
                                }
                            });
                        }
                    }
                ]
            });

            //初始化功能编辑窗口
            $('<div id="resourceFunEditorWindow"></div>').appendTo('body').window({
                href: 'javascript:void(0);',
                title: '新建/编辑功能点',
                width: 320,
                top: $(window).height() * 0.25,
                closed: true
            });
        });

        //编辑成功后
        function OnResourceFunEditSuccess() {
            $('#resourceFunEditorWindow').window('close');
            $('#resourceFunList').datagrid('reload');
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="resourceFunList">
    </div>
    </form>
</body>
</html>